package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20240915060148CreateUsersTable struct {
}

// Signature The unique signature for the migration.
func (r *M20240915060148CreateUsersTable) Signature() string {
	return "20240915060148_create_users_table"
}

// Up Run the migrations.
func (r *M20240915060148CreateUsersTable) Up() error {
	if !facades.Schema().HasTable("user") {
		return facades.Schema().Create("user", func(table schema.Blueprint) {
			table.ID("id")
			table.String("name").Comment("用户名")
			table.String("email").Nullable().Comment("邮箱")
			table.String("password").Comment("密码")
			table.Timestamp("pwd_update_at").Nullable().Comment("密码更新时间")
			table.String("phone").Nullable().Comment("手机号")
			table.String("avatar").Nullable().Comment("头像")
			table.Integer("accumulated_points").Default(0).Comment("累计积分")
			table.Integer("level").Default(0).Comment("当前等级")
			table.Integer("status").Default(0).Comment("状态")
			table.Integer("gender").Default(0).Comment("性别")
			table.String("last_login_ip").Nullable().Comment("最后登录IP")
			table.Timestamp("last_login_time").Nullable().Comment("最后登录时间")
			table.TimestampsTz()

			table.Unique("name")
		})
	}
	return nil
}

// Down Reverse the migrations.
func (r *M20240915060148CreateUsersTable) Down() error {
	return facades.Schema().DropIfExists("user")
}
